package com.activenetwork.smlite.testcase.events.createEvents.basics;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.activenetwork.custom.uielement.decorate.IdentifierFactory;
import com.activenetwork.smlite.page.event.EventDetailView.EventBasicSubview;
import com.activenetwork.smlite.snippet.EventsSnippet;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.verification.VerificationAction;
import com.activenetwork.util.verification.checkCalendarType;
import com.activenetwork.util.verification.checkDropdownType;
import com.activenetwork.util.verification.checkText;
import com.activenetwork.util.verification.checkType;
import com.activenetwork.util.verification.gson.FailureAssertion;
import com.activenetwork.util.verification.gson.FailurePoint;

public class Basics001 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(Basics001.class);
	
	@Test
	public void  Verify_UI_of_Event_Creation(){
		loginBusiness.login();
		
		EventBasicSubview eventBasicSubview = EventsSnippet.gotoAddEventPage();
		logger.info("Verify Basic Message");
		try{
			webDriver.findElement(By.cssSelector(".autotest-panel-eventbasicsubview div#nexus-basic-help p"));
		}catch(NoSuchElementException e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics001.class.getName(), "VerifyBasicMessage", "Unable to find the basic message"));
		}
		
		logger.info("Verify the Basic can hide/show");
		try{
			WebElement helpDiv = webDriver.findElement(By.cssSelector(".autotest-html-eventbasicsubview #nexus-basic-help"));
			String value = helpDiv.getAttribute("class").trim();
			if(StringUtils.equalsIgnoreCase(value, "collapse")){ //hide
				eventBasicSubview = eventBasicSubview.showBasicMsg();
				eventBasicSubview = eventBasicSubview.hideBasicMsg();
			}else{
				eventBasicSubview = eventBasicSubview.hideBasicMsg();
				eventBasicSubview = eventBasicSubview.showBasicMsg();
			}
		}catch(Exception e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics001.class.getName(), "VerifyShowHideBasicMessage", "Unable to show/hide the basic message"));
		}
		
		logger.info("Verify event title textbox");
		new checkType("EventBasicSubview", "eventTitle", "text", Basics001.class.getName()).verify();
		
		logger.info("Verify event location textbox");
		new checkType("EventBasicSubview", "eventLocation", "text", Basics001.class.getName()).verify();
		
		logger.info("Verify event location add button");
		new checkType("EventBasicSubview", "addLocation", "button", Basics001.class.getName()).verify();
		
		logger.info("Verify event category dropdown");
		new checkDropdownType("EventBasicSubview", "eventCategory", Basics001.class.getName()).verify();
		
		logger.info("Verify event length radio");
		new checkType("EventBasicSubview", "eventLengthSingleDay", "radio", Basics001.class.getName()).verify();
		new checkType("EventBasicSubview", "eventLengthMultiDay", "radio", Basics001.class.getName()).verify();
		
		logger.info("Verify default event length is multiple day");
		new VerificationAction(){

			@Override
			public void verify() {
				WebElement element = IdentifierFactory.createWebElement("EventBasicSubview", "eventLengthSingleDay");
				String checked = element.getAttribute("checked");
				if(checked != null){
					EnvContext.failurePointTL.get().add(
							new FailurePoint(Basics001.class.getName(), "Verify multi-day default checked", "Single day is checked by default"));
				}
			}
			
		}.verify();
		
		logger.info("Verify start/end date is calendar type");
		new checkCalendarType("EventBasicSubview", "eventStartDate", Basics001.class.getName());
		new checkCalendarType("EventBasicSubview", "eventEndDate", Basics001.class.getName());
		
		logger.info("Verify tag textbox");
		new checkType("EventBasicSubview", "eventTag", "text", Basics001.class.getName()).verify();
		
		logger.info("Verify add tag button");
		new checkType("EventBasicSubview", "addTag", "button", Basics001.class.getName()).verify();
		
		logger.info("since next step feature is enabled, verify sourcing button");
		WebElement element = IdentifierFactory.createWebElement("EventBasicSubview", "nextStep");
		new checkText(element.findElement(By.xpath(".//span")), "Registration Form", Basics001.class.getName()).verify();
		
		// logout
		loginBusiness.logout();
		
		// Popup failures
		FailureAssertion.pop(Basics001.class);
	}
	



}
